﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace MindBreaker.GameObjects
{
    public class PhysicObject : GameObject
    {
        // Class properties
        private float _speedX;
        private float _speedY;

        public PhysicObject(Game game, String textureKey, int posX, int posY, int speedX, int speedY)
            : base(game, textureKey, posX, posY)
        {
            this.SpeedX = speedX;
            this.SpeedY = speedY;
        }

        // Properties access
        public float SpeedX
        {
            get { return _speedX; }
            set { _speedX = value; }
        }

        public float SpeedY
        {
            get { return _speedY; }
            set { _speedY = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns>
        /// -1 if reach min Y
        /// -2 if reach maxY
        /// 0 if is not out of area
        /// 1 if reach min X
        /// 2 if reach max X
        /// </returns>
        public int isOutOfArea()
        {
            int outOfArea = 0;

            //extrem coordonates values
            int minX = 0;
            int minY = 0;
            int maxX = this.GraphicsDevice.Viewport.Width;
            int maxY = this.GraphicsDevice.Viewport.Height;

            //Wall collision
            if (this.PosX <= minX) {
                //Dépassement en min X
                outOfArea = 1;
            } else if (this.PosX + this.Width >= maxX) {
                //Dépassement en max X
                outOfArea = 2;
            } else if (this.PosY <= minY) {
                //Dépassement en min Y
                outOfArea = -1;
            } else if (this.PosY + this.Height >= maxY) {
                // Dépassement en max Y
                outOfArea = -2;
            }

            return outOfArea;
        }

        public void reverseSpeedX()
        {
            this.SpeedX *= -1;
        }

        public void reverseSpeedY()
        {
            this.SpeedY *= -1;
        }

        public override void Update(GameTime gameTime)
        {
            // Move the object
            this.PosX += this.SpeedX;
            this.PosY += this.SpeedY;

            base.Update(gameTime);
        }


    }
}
